﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
namespace WPFExcelReport
{
    public partial class UIWASTKE : ViewBase
    {    
        public VWASTKE TMV
        {
            get
            {
                return (VWASTKE)MV;
            }
        }
        #region ==WARP===========
        public static readonly DependencyProperty WARPProperty = DependencyProperty.Register("WARP",
            typeof(string), typeof(UIWASTKE),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWARPChanged));
        public string WARP
        {
            get
            {
                return (string)GetValue(WARPProperty);
            }
            set
            {
                SetValue(WARPProperty, value);
                OnWARPChg();
            }
        }
        private static void OnWARPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWASTKE;
            if (src != null)
            {
                src.WARP = (string)e.NewValue;
            }
        }
        public virtual void OnWARPChg()
        { }
        #endregion

        #region ==WTKEY===========
        public static readonly DependencyProperty WTKEYProperty = DependencyProperty.Register("WTKEY",
        typeof(string), typeof(UIWASTKE),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWTKEYChanged));
        public string WTKEY
        {
            get
            {
                return (string)GetValue(WTKEYProperty);
            }
            set
            {
                SetValue(WTKEYProperty, value);
                OnWTKEYChg();
            }
        }
        private static void OnWTKEYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWASTKE;
            if (src != null)
            {
                src.WTKEY = (string)e.NewValue;
            }
        }
        public virtual void OnWTKEYChg()
        { }
        #endregion
        public UIWASTKE()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
        }

        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            if (dwMaster == null)
            {
                KEY = "";
                WARP = "";
            }
            else
            {  
                KEY = "R"+TMV.WAKART + TMV.WAKVAR+TMV.WAKWCOL+TMV.WAKPOS;
                WARP = "B"+TMV.WAKKART + TMV.WAKKVAR + TMV.WAKKFARBE;
            }
        }
        public override void LOADBYAUF()
        {          
            TBMain.Clear();
            if (ORDERNUM.Length < 33)
                return;
            PM["ART"] = ORDERNUM.Substring(1, 20);
            PM["VAR"] = ORDERNUM.Substring(21, 2);
            PM["FARBE"] = ORDERNUM.Substring(23, 10); 
            SResult = TMV.LOADBYWF(PM);
            MergeData(SResult, true); 
            base.LOADBYAUF();
        }
    }
}
